package arm.mbean;

import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;

import org.apache.log4j.Logger;

import sun.management.ManagementFactory;

@SuppressWarnings("restriction")
public class ArmMBeanServer {

	private static final Logger log = Logger.getLogger(ArmMBeanServer.class);
	private String defaultdomain;
	private MBeanServer server;
	private boolean localExisteServer;
	
	public MBeanServer createMBeanServer()
	{
		if(this.localExisteServer)
		{
			server = this.createMBeanServer(this.localExisteServer);
			log.info("create platform MBean Server finished");
		}
		if(server==null)
		{
			server = MBeanServerFactory.createMBeanServer(defaultdomain);
			log.info("create default MBean Server finished");
		}
		return server;
	}

	private MBeanServer createMBeanServer(boolean localExisteServer) {
		if(localExisteServer&&server==null)
		{
			server = ManagementFactory.createPlatformMBeanServer();
		}
		return server;
	}

	public boolean isLocalExisteServer() {
		return localExisteServer;
	}

	public void setLocalExisteServer(boolean localExisteServer) {
		this.localExisteServer = localExisteServer;
	}

	public void setDefaultdomain(String defaultdomain) {
		this.defaultdomain = defaultdomain;
	}

	
	
}
